Skip to content

Conversation

@aselimc
Copy link

@aselimc aselimc commented Aug 14, 2025

Hello,

First of all I use Windows, so this test was only done in Windows, not in Linux

REPO_DIR = r"C:\Users\aselimc\Repos\dinov3"
weights = r"C:\Users\aselimc\Repos\dinov3\checkpoints\dinov3_vit7b16_pretrain_sat493m-a6675841.pth"
dinov3_vit7b16 = torch.hub.load(REPO_DIR, 'dinov3_vit7b16', source='local', weights=weights)

The current implementation creates duplicate model weights in .cache/torch/ even if the weights have already been downloaded. This is caused by torch.hub.load_state_dict_from_url. As an example

Downloading: "file:///C:/Users/aselimc/Repos/dinov3/checkpoints/dinov3_vit7b16_pretrain_sat493m-a6675841.pth" to [C:\Users\aselimc/.cache\torch\hub\checkpoints\dinov3_vit7b16_pretrain_sat493m-a6675841.pth](file:///C:/Users/aselimc/.cache/torch/hub/checkpoints/dinov3_vit7b16_pretrain_sat493m-a6675841.pth)
100%|██████████| 25.0G/25.0G [00:10<00:00, 2.53GB/s]

my local file is copied into cache.

Therefore, I suggest using torch.load in case a local path is given to load state_dict.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 14, 2025
@aselimc aselimc marked this pull request as ready for review August 14, 2025 20:09
@aselimc aselimc changed the title Bugfix: Prevent weight file duplicate Bugfix: Prevent model weights file duplicate to cache Aug 14, 2025
@forensicmike

This comment was marked as resolved.

@forensicmike
Copy link

Nevermind, I found them. Yeah, this should be fixed for sure!

@aselimc
Copy link
Author

aselimc commented Aug 15, 2025

As I realized more into it, this behavior is not only for backbones but also for downstream heads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants